﻿#region Imports
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Security.Principal;
#endregion

namespace Project.Model.Rights
{
	/// <summary>
	/// 功能：用户 实体类
	///       User 对象映射表 'rights_User'
    ///       实现了接口: IPrincipal
	/// 作者：tanghh
	/// 日期：2010-06-11
	/// </summary>
	[Serializable]
    public class User : IPrincipal
    {
        #region Property Members		
		/// <summary>
		/// Id 主键Id
		/// </summary>
		public virtual Guid Id { get; set; }
		
		/// <summary>
		/// Version 版本
		/// </summary>
		public virtual int Version { get; set; }
		
		/// <summary>
		/// Code 编码
		/// </summary>
		public virtual string Code { get; set; }
		
		/// <summary>
		/// Name 用户名
		/// </summary>
		public virtual string Name { get; set; }
		
		/// <summary>
		/// IsActivate 是否邮件激活
		/// </summary>
		public virtual bool IsActivate { get; set; }
		
		/// <summary>
		/// IsApprove 是否审核
		/// </summary>
		public virtual bool IsApprove { get; set; }
		
		/// <summary>
		/// IsLock 是否锁定
		/// </summary>
		public virtual bool IsLock { get; set; }
		
		/// <summary>
		/// Password 密码
		/// </summary>
		public virtual string Password { get; set; }
		
		/// <summary>
		/// PlainText 明文密码
		/// </summary>
		public virtual string PlainText { get; set; }
		
		/// <summary>
		/// LastLoginDate 最后登录日期
		/// </summary>
		public virtual DateTime LastLoginDate { get; set; }
		
		/// <summary>
		/// CreateTime 创建时间
		/// </summary>
		public virtual DateTime CreateTime { get; set; }
		
		/// <summary>
		/// UpdateTime 更新时间
		/// </summary>
		public virtual DateTime UpdateTime { get; set; }
		
        #endregion

        #region IPrincipal的接口函数    摘自：Suteki.Shop
        public virtual IIdentity Identity
        {
            get
            {
                bool isAuthenticated = true; //!(Role.Code == Role.GuestId.ToString());
                return new Identity(isAuthenticated, this.Name);
            }
        }

        public virtual bool IsInRole(string role)
        {
            return this.Role.Name == role;
        }

        #endregion

        #region 其他函数    摘自：Suteki.Shop
        //public virtual void Validate()
        //{
        //    Validator validator = new Validator
        //    {
        //        () => Name.Label("Name").IsRequired(),
        //        () => Password.Label("Password").IsRequired(),
        //    };

        //    validator.Validate();
        //}

        #endregion

        /// <summary>
        /// 用户简档
        /// </summary>
        public virtual UserProfile UserProfile { get; set; }

        /// <summary>
        /// 用户角色
        /// </summary>
        public virtual Role Role { get; set; }

        /// <summary>
        /// 用户的角色集
        /// </summary>
        //public virtual IList<Role> Roles { get; set; }
    }

}

